func sortedSquares(nums []int) []int {
    n := len(nums)
    l, r := 0, n - 1
    ans := make([]int, n)

    for pos:=n-1; pos>=0 ; pos-- {
        if ln, rn := nums[l]*nums[l], nums[r]*nums[r]; ln < rn {
            ans[pos] = rn
            r--
        }else{
            ans[pos] = ln
            l++
        }
    }
    return ans
}